package com.sky.controller.admin;

import com.sky.constant.StatusConstant;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * @Auth: cdz
 * @Desc:
 * @Date: 2023/3/9 18:05
 */
@RestController
@Slf4j
@Api(tags = "商铺状态相关接口")
@RequestMapping("/admin/shop")
public class ShopAdminController {

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 功能描述: 设置商铺状态
     * @return : com.sky.result.Result
     */
    @ApiOperation("设置商铺状态")
    @PutMapping("/{status}")
    public Result update(@PathVariable Integer status) {
        //将状态存在redis数据库
        stringRedisTemplate.opsForValue().set(StatusConstant.SHOP_STATUS,Integer.toString(status));
        //redisTemplate.opsForValue().set(StatusConstant.SHOP_STATUS, status);
        return Result.success();
    }

    /**
     * 功能描述: 展示商铺状态
     *
     * @return : com.sky.result.Result
     */
    @GetMapping("/status")
    @ApiOperation("商铺展示状态")
    public Result getStatus() {
        int status = Integer.parseInt(stringRedisTemplate.opsForValue().get(StatusConstant.SHOP_STATUS));
        //int status = (int) redisTemplate.opsForValue().get(StatusConstant.SHOP_STATUS);
        return Result.success(status);
    }
}
